package com.fxsh168.server.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.fxsh168.server.R;
import com.fxsh168.server.base.BaseActivity;
import com.fxsh168.server.interfaces.Constant;


public class ReginNameActivity extends BaseActivity implements View.OnClickListener {
    private EditText mPutName, mPutIDNumber, mPutCarBrand, mPutCarNumber, mPutCarColor, mPutJiaShiZhengHao, mPutXingShiZhengJianHao;
    private String phone, mPass, mYaoText;
    private TextView teChooseFast, teChooseOnly;
    private String ChooseWho;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recruitment_driver);
        teChooseOnly = (TextView) findViewById(R.id.teChooseOnly);
        teChooseFast = (TextView) findViewById(R.id.teChooseFast);
        mPutName = (EditText) findViewById(R.id.putName);
        mPutIDNumber = (EditText) findViewById(R.id.putIDNumber);
        mPutCarBrand = (EditText) findViewById(R.id.putCarBrand);
        mPutCarNumber = (EditText) findViewById(R.id.putCarNumber);
        mPutCarColor = (EditText) findViewById(R.id.putCarColor);
        mPutJiaShiZhengHao = (EditText) findViewById(R.id.putJiaShiZhengHao);
        mPutXingShiZhengJianHao = (EditText) findViewById(R.id.putXingShiZhengJianHao);
        teChooseOnly.setOnClickListener(this);
        teChooseFast.setOnClickListener(this);
        phone = getIntent().getStringExtra("phone");
        mPass = getIntent().getStringExtra("mPass");
        mYaoText = getIntent().getStringExtra("yao");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.teChooseFast:
                ChooseWho = "1";
                teChooseFast.setBackgroundColor(getResources().getColor(R.color.loginBtn));
                teChooseOnly.setBackgroundColor(getResources().getColor(R.color.loginText));
                break;
            case R.id.teChooseOnly:
                ChooseWho = "4";
                teChooseOnly.setBackgroundColor(getResources().getColor(R.color.loginBtn));
                teChooseFast.setBackgroundColor(getResources().getColor(R.color.loginText));
                break;
        }
    }

    String getName, getIDNumber, getCarBrand, getCarNumber, getCarCorlor, getJiaShiZheng, getXingShiZheng;

    //下一步
    public void btnNext(View view) {
        //获取各个输入框数据
        getName = mPutName.getText().toString().trim();
        getIDNumber = mPutIDNumber.getText().toString().trim();
        getCarBrand = mPutCarBrand.getText().toString().trim();
        getCarNumber = mPutCarNumber.getText().toString().trim();
        getCarCorlor = mPutCarColor.getText().toString().trim();
        getJiaShiZheng = mPutJiaShiZhengHao.getText().toString().trim();
        getXingShiZheng = mPutXingShiZhengJianHao.getText().toString().trim();

        //存储在sharepreferrences中方便下一页获取
        SharedPreferences sp = getSharedPreferences(Constant.RECRUITDRIVCLSS, MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("getName", getName);
        editor.putString("getIDNumber", getIDNumber);
        editor.putString("getCarBrand", getCarBrand);
        editor.putString("getCarNumber", getCarNumber);
        editor.putString("getCarCorlor", getCarCorlor);
        editor.putString("getJiaShiZheng", getJiaShiZheng);
        editor.putString("getXingShiZheng", getXingShiZheng);
        editor.commit();
        Intent intent = new Intent(this, ReginPhotoActivity.class);
        intent.putExtra("phone", phone);
        intent.putExtra("mPass", mPass);
//        intent.putExtra("yao", mYaoText);
        intent.putExtra("choosewho", ChooseWho);
        if (CanJump()) {
            startActivityForResult(intent, Constant.RECRUIT1REQUESTCODE);
        }

    }

    private boolean CanJump() {
        if (TextUtils.isEmpty(ChooseWho)) {
            showToast("请选择注册类型");
        } else if (TextUtils.isEmpty(getName)) {
            showToast("请输入名字");
        } else if (TextUtils.isEmpty(getIDNumber)) {
            showToast("请填写身份证号");
        } else if (getIDNumber.length() < 16) {
            showToast("请填写正确的身份证号");
        } /*else if (TextUtils.isEmpty(getCarBrand)) {
            showToast("请填写汽车品牌");
        } */else if (TextUtils.isEmpty(getCarNumber)) {
            showToast("请填写车牌号");
        }/* else if (TextUtils.isEmpty(getCarCorlor)) {
            showToast("请输入汽车颜色");
        } else if (TextUtils.isEmpty(getJiaShiZheng)) {
            showToast("请输入驾驶证号码");
        } else if (TextUtils.isEmpty(getXingShiZheng)) {
            showToast("请输入行驶证号");
        } */else {
            return true;
        }
        return false;
    }
}
